const mutations = {
  setShowHeaderFlag(state, payload) {
    state.showHeader = payload
  },

  handleLogin(state, payload) {
    state.userInfo = { ...state.userInfo, ...payload }
    state.isLogin = true;

    localStorage.setItem("userID", state.userInfo.userID)
  },

  handleLogout(state) {
    state.userInfo = null;
    state.isLogin = false;
    localStorage.clear();
  }
}

const homeMutations = {
  setArticleInfo(state, payload) {
    const { category, list, isLoadMore } = payload;
    state.articleCategory = category;
    const originList = state.articleList[category];
    if(!originList) {
      state.articleList[category] = list;
    } else {
      state.articleList[category] = isLoadMore ? state.articleList[category].concat(list) : list
    }
  }
}

export default { ...mutations, ...homeMutations }